/**
 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * For the applicable distribution terms see the license.txt -file, included in
 * the distribution.
 */

#ifndef DRMFILE_P_H
#define DRMFILE_P_H

#include <qglobal.h>
#include <caf/content.h>

using namespace ContentAccess;
class DRMFile;

/*!
  \class DRMFilePrivate
  \brief Content Access Framework (CAF) wrapper implementation
*/

class DRMFilePrivate
{
public:
    /*!
      Constructor
    */
    explicit DRMFilePrivate();
    /*!
      Destructor
    */
    virtual ~DRMFilePrivate();

public:
    /*!
      Opens either DRM encrypted file package or non-protected file
      NOTE: Access to unprotected content is unrestricted by CAF thus regular files can
      be opened and read successfully
    */
    int open(const QString & fileName);

    /*!
      Reads the whole data or requested length into allocated memory buffer.
     'data'   - reference to pointer on allocated memory buffer.
              It is client's responcibility to release allocated memory
     'length' - requested data length to read, if it is equal to '0' it will read the whole file
     'index' - data item index in the container
    */
    int read(uchar*& data, int length = 0, int index = 0);
    /*!
      Closes file or DRM file package
    */
    void close();
    /*!
      Returns opened file or DRM file package size
    */
    int size(int index = 0);

    inline int count()
    {
        return (CAF_data.Count());
    }

    /*!
      Allocates memory for data item name or NULL if error happens
      'index'  - data item index in the DRM container

      Special cases for the EContentID field
        KNullDesC16() - ""
      A zero length EContentID is used to refer to the entire file.
      If a file is opened this way, no embedded items are visible in the DRM container
    */
    const ushort* getStringAttr(int index, int& len, TStringAttribute attr = EContentID) const;
    
private:
    /*!
      Function helper to 'open' method
    */
    void openL(const TDesC& fileName);
   
private:
    CContent *CAF_file;             // content container
    RPointerArray<CData> CAF_data;  // content container data array
    TBool intentExecuted;           //'in-progress' flag
};

#endif // DRMFILE_P_H
